package start;

import java.util.Properties;

import javax.naming.*;
import javax.jms.*;

public class Test implements MessageListener {
        private static MessageConsumer _consumer;

        public static void main(String args[]) throws Exception {
                Properties env = new Properties();
                env.put("org.omg.CORBA.ORBInitialHost", "127.0.0.1"); 
                env.put("org.omg.CORBA.ORBInitialPort", "3700"); 
                env.put("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
                InitialContext ctx = new InitialContext(env);
                QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ctx
                                .lookup("LibManQueueFactory");
                QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
                QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue) ctx.lookup("LibManQueue");
                queueConnection.start();
                QueueSender sender = queueSession.createSender(queue);
                QueueReceiver receiver = queueSession.createReceiver(queue);
                TextMessage msg = (TextMessage)receiver.receive();
                System.out.println(msg.getText());
                // Close the connection
//              con.close();
//              System.out.println("Connection closed");

        }

        @Override
        public void onMessage(Message arg0) {
                // Start the connection, causing message delivery to begin
                // Receive the messages sent to the destination
                TextMessage msg = (TextMessage) arg0;
                try {
                        System.out.println(msg.getText());
                } catch (JMSException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}